<?php
declare(strict_types=1);
namespace Service\GoodsService;
use Service\BaseService;
use App\Model\BbcModel\GoodsClass;
use Service\CacheService\CacheProviderService as Cache;
/**
 * 渠道商品分类服务中心
 * @author chenshubo
 */
class ChannelGoodsClassService extends BaseService
{
    /**
     * 获取渠道指定范围的分类树形结构
     * @param int $cid
     * @param array $class_ids
     */
    public function getGoodsClassByThirdClassIDs(int $cid, array $class_ids = [])
    {
        return GoodsClass::instance()
        ->select([
            'id', 
            'name', 
            'icon', 
            'pid',
            'description'
        ])
        ->where('cid',$cid)
        ->whereIn('id',$class_ids)
        ->get()
        ->toArray();
    }
 
    /**
     * 获取渠道所有分类数据
     * @param int $cid
     * @param array $class_ids
     */
    public function getGoodsClass(int $cid)
    {
        $cache_key = "ChannelGoodsClass_getGoodsClass_{$cid}";
        $data      = Cache::getCacheByKey($cache_key);
        if(empty($data)){
            $data=GoodsClass::instance()
            ->select([
                'id',
                'name',
                'icon',
                'pid',
                'description'
            ])
            ->where('cid',$cid)
            ->get()
            ->toArray();
            Cache::cacheBySetKeyValue($cache_key, $data, 300);
        }
        return $data;
    }
}